package com.cloud.code.牛客网;

import java.util.*;

/**
 * 全排列Test
 */
public class Test48 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            int[] nums = new int[n];
            for (int i = 0; i < n; i++) {
                nums[i] = i + 1;
            }

            Deque<Integer> path = new ArrayDeque();
            List<String> res = new ArrayList<>();
            boolean[] used = new boolean[n];
            dfs(nums, 0, n, used, path, res);

            System.out.println(res);
        }
    }

    private static void dfs(int[] nums, int depth, int len, boolean[] used, Deque<Integer> path, List<String> res) {

        if (depth == len) {
            String temp = Arrays.toString(new Deque[]{path}).replace("\\W+", "");
            res.add(temp);
            return;
        }

        for (int i = 0; i < len; i++) {
            if (used[i]) {
                continue;
            }
            path.addLast(nums[i]);
            used[i] = true;
            dfs(nums, depth + 1, len, used, path, res);
            path.removeLast();
            used[i] = false;
        }
    }
}
